package com.neo.design.chain.approve;

import com.neo.design.chain.ChainHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * 老板审批处理
 *
 * @see com.neo.design.chain.approve.ApproveHandler
 * @author Kevin
 */
@Order(3)
@Component
@Slf4j
@DependsOn("managerApproveHandler")
public class BossApproveHandler implements ApproveHandler {

    private ChainHandler<ApproveRequest, ApproveResult> next;

    @Override
    public ApproveResult handleRequest(ApproveRequest request) {
        if (request.getStatus() == 3) {
            return ApproveResult.builder().message("老板审批").build();
        }
        log.info("老板已经审批过了，交由下一节点审批");
        Assert.notNull(next, "审批流程已结束，或不支持该操作。");
        return next.handleRequest(request);
    }

    @Override
    public void setNext(ChainHandler<ApproveRequest, ApproveResult> next) {
        this.next = next;
    }
}
